<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>timezone_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_i18n_timezone_test.js.html">timezone_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.i18n.TimeZoneTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.i18n.TimeZoneTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.i18n.TimeZone&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>
<a name="line21"></a>// Where could such data be found
<a name="line22"></a>// In js_i18n_data in http://go/i18n_dir, we have a bunch of files with names
<a name="line23"></a>// like TimeZoneConstant__&lt;locale&gt;.js
<a name="line24"></a>// We strongly discourage you to use them directly as those data can make
<a name="line25"></a>// your client code bloated. You should try to provide this data from server
<a name="line26"></a>// in a selective manner. In typical scenario, user&#39;s time zone is retrieved
<a name="line27"></a>// and only data for that time zone should be provided.
<a name="line28"></a>// This piece of data is in JSON format. It requires double quote.
<a name="line29"></a>var americaLosAngelesData = {
<a name="line30"></a>  &#39;transitions&#39;: [
<a name="line31"></a>    2770, 60, 7137, 0, 11506, 60, 16041, 0, 20410, 60, 24777, 0, 29146, 60,
<a name="line32"></a>    33513, 0, 35194, 60, 42249, 0, 45106, 60, 50985, 0, 55354, 60, 59889, 0,
<a name="line33"></a>    64090, 60, 68625, 0, 72994, 60, 77361, 0, 81730, 60, 86097, 0, 90466, 60,
<a name="line34"></a>    94833, 0, 99202, 60, 103569, 0, 107938, 60, 112473, 0, 116674, 60, 121209,
<a name="line35"></a>    0, 125578, 60, 129945, 0, 134314, 60, 138681, 0, 143050, 60, 147417, 0,
<a name="line36"></a>    151282, 60, 156153, 0, 160018, 60, 165057, 0, 168754, 60, 173793, 0,
<a name="line37"></a>    177490, 60, 182529, 0, 186394, 60, 191265, 0, 195130, 60, 200001, 0,
<a name="line38"></a>    203866, 60, 208905, 0, 212602, 60, 217641, 0, 221338, 60, 226377, 0,
<a name="line39"></a>    230242, 60, 235113, 0, 238978, 60, 243849, 0, 247714, 60, 252585, 0,
<a name="line40"></a>    256450, 60, 261489, 0, 265186, 60, 270225, 0, 273922, 60, 278961, 0,
<a name="line41"></a>    282826, 60, 287697, 0, 291562, 60, 296433, 0, 300298, 60, 305337, 0,
<a name="line42"></a>    309034, 60, 314073, 0, 317770, 60, 322809, 0, 326002, 60, 331713, 0,
<a name="line43"></a>    334738, 60, 340449, 0, 343474, 60, 349185, 0, 352378, 60, 358089, 0,
<a name="line44"></a>    361114, 60, 366825, 0, 369850, 60, 375561, 0, 378586, 60, 384297, 0,
<a name="line45"></a>    387322, 60, 393033, 0, 396058, 60, 401769, 0, 404962, 60, 410673, 0,
<a name="line46"></a>    413698, 60, 419409, 0, 422434, 60, 428145, 0, 431170, 60, 436881, 0,
<a name="line47"></a>    439906, 60, 445617, 0, 448810, 60, 454521, 0, 457546, 60, 463257, 0,
<a name="line48"></a>    466282, 60, 471993, 0, 475018, 60, 480729, 0, 483754, 60, 489465, 0,
<a name="line49"></a>    492490, 60, 498201, 0, 501394, 60, 507105, 0, 510130, 60, 515841, 0,
<a name="line50"></a>    518866, 60, 524577, 0, 527602, 60, 533313, 0, 536338, 60, 542049, 0,
<a name="line51"></a>    545242, 60, 550953, 0, 553978, 60, 559689, 0, 562714, 60, 568425, 0,
<a name="line52"></a>    571450, 60, 577161, 0, 580186, 60, 585897, 0, 588922, 60, 594633, 0
<a name="line53"></a>  ],
<a name="line54"></a>  &#39;names&#39;: [&#39;PST&#39;, &#39;Pacific Standard Time&#39;, &#39;PDT&#39;, &#39;Pacific Daylight Time&#39;],
<a name="line55"></a>  &#39;id&#39;: &#39;America/Los_Angeles&#39;,
<a name="line56"></a>  &#39;std_offset&#39;: -480
<a name="line57"></a>};
<a name="line58"></a>
<a name="line59"></a>function testIsDaylightTime() {
<a name="line60"></a>  var usPacific = goog.i18n.TimeZone.createTimeZone(americaLosAngelesData);
<a name="line61"></a>  var dt = new Date(2007, 7 - 1, 1);
<a name="line62"></a>  assertTrue(usPacific.isDaylightTime(dt));
<a name="line63"></a>  // 2007/03/11 2:00am has daylight change. We set time through UTC so that
<a name="line64"></a>  // this test won&#39;t be affected by browser&#39;s local time handling.
<a name="line65"></a>  dt = new Date(2007, 3 - 1, 11);
<a name="line66"></a>  // The date above is created with a timezone of the computer it is run on.
<a name="line67"></a>  // Therefore the UTC day has to be set explicitly to be sure that the date
<a name="line68"></a>  // is correct for timezones east of Greenwich  where 2007/3/11 0:00 is still
<a name="line69"></a>  // 2007/03/10 in UTC.
<a name="line70"></a>  dt.setUTCDate(11);
<a name="line71"></a>  dt.setUTCHours(2 + 8);
<a name="line72"></a>  dt.setUTCMinutes(1);
<a name="line73"></a>  assertTrue(usPacific.isDaylightTime(dt));
<a name="line74"></a>  dt.setUTCHours(1 + 8);
<a name="line75"></a>  dt.setUTCMinutes(59);
<a name="line76"></a>  assertTrue(!usPacific.isDaylightTime(dt));
<a name="line77"></a>
<a name="line78"></a>  dt = new Date(2007, 11 - 1, 4);
<a name="line79"></a>  // Set the UTC day explicitly to make it work in timezones east of
<a name="line80"></a>  // Greenwich.
<a name="line81"></a>  dt.setUTCDate(4);
<a name="line82"></a>  dt.setUTCHours(2 + 7);
<a name="line83"></a>  dt.setUTCMinutes(1);
<a name="line84"></a>  assertTrue(!usPacific.isDaylightTime(dt));
<a name="line85"></a>
<a name="line86"></a>  // there seems to be a browser bug. local time 1:59am should still be PDT.
<a name="line87"></a>  dt.setUTCHours(0 + 7);
<a name="line88"></a>  dt.setUTCMinutes(59);
<a name="line89"></a>  assertTrue(usPacific.isDaylightTime(dt));
<a name="line90"></a>}
<a name="line91"></a>
<a name="line92"></a>function testGetters() {
<a name="line93"></a>  var date = new Date();
<a name="line94"></a>  var usPacific = goog.i18n.TimeZone.createTimeZone(americaLosAngelesData);
<a name="line95"></a>  if (usPacific.isDaylightTime(date)) {
<a name="line96"></a>    assertEquals(420, usPacific.getOffset(date));
<a name="line97"></a>  } else {
<a name="line98"></a>    assertEquals(480, usPacific.getOffset(date));
<a name="line99"></a>  }
<a name="line100"></a>  assertEquals(&#39;America/Los_Angeles&#39;, usPacific.getTimeZoneId());
<a name="line101"></a>  assertObjectEquals(americaLosAngelesData, usPacific.getTimeZoneData());
<a name="line102"></a>}
<a name="line103"></a>
<a name="line104"></a>function testNames() {
<a name="line105"></a>  var usPacific = goog.i18n.TimeZone.createTimeZone(americaLosAngelesData);
<a name="line106"></a>  var dt = new Date(2007, 7 - 1, 1);
<a name="line107"></a>  assertTrue(usPacific.isDaylightTime(dt));
<a name="line108"></a>  assertEquals(&#39;PDT&#39;, usPacific.getShortName(dt));
<a name="line109"></a>  assertEquals(&#39;Pacific Daylight Time&#39;, usPacific.getLongName(dt));
<a name="line110"></a>
<a name="line111"></a>  dt = new Date(2007, 12 - 1, 1);
<a name="line112"></a>  assertTrue(!usPacific.isDaylightTime(dt));
<a name="line113"></a>  assertEquals(&#39;PST&#39;, usPacific.getShortName(dt));
<a name="line114"></a>  assertEquals(&#39;Pacific Standard Time&#39;, usPacific.getLongName(dt));
<a name="line115"></a>}
<a name="line116"></a>
<a name="line117"></a>function testSimpleTimeZonePositive() {
<a name="line118"></a>  var date = new Date();
<a name="line119"></a>  var simpleTimeZone = goog.i18n.TimeZone.createTimeZone(480);
<a name="line120"></a>  assertEquals(480, simpleTimeZone.getOffset(date));
<a name="line121"></a>  assertEquals(&#39;GMT-08:00&#39;, simpleTimeZone.getGMTString(date));
<a name="line122"></a>  assertEquals(&#39;Etc/GMT+8&#39;, simpleTimeZone.getTimeZoneId());
<a name="line123"></a>  assertEquals(&#39;UTC-8&#39;, simpleTimeZone.getLongName(date));
<a name="line124"></a>  assertEquals(&#39;UTC-8&#39;, simpleTimeZone.getShortName(date));
<a name="line125"></a>  assertEquals(&#39;-0800&#39;, simpleTimeZone.getRFCTimeZoneString(date));
<a name="line126"></a>  assertEquals(false, simpleTimeZone.isDaylightTime(date));
<a name="line127"></a>
<a name="line128"></a>  simpleTimeZone = goog.i18n.TimeZone.createTimeZone(630);
<a name="line129"></a>  assertEquals(630, simpleTimeZone.getOffset(date));
<a name="line130"></a>  assertEquals(&#39;GMT-10:30&#39;, simpleTimeZone.getGMTString(date));
<a name="line131"></a>  assertEquals(&#39;Etc/GMT+10:30&#39;, simpleTimeZone.getTimeZoneId());
<a name="line132"></a>  assertEquals(&#39;UTC-10:30&#39;, simpleTimeZone.getLongName(date));
<a name="line133"></a>  assertEquals(&#39;UTC-10:30&#39;, simpleTimeZone.getShortName(date));
<a name="line134"></a>  assertEquals(&#39;-1030&#39;, simpleTimeZone.getRFCTimeZoneString(date));
<a name="line135"></a>  assertEquals(false, simpleTimeZone.isDaylightTime(date));
<a name="line136"></a>}
<a name="line137"></a>
<a name="line138"></a>function testSimpleTimeZoneNegative() {
<a name="line139"></a>  var date = new Date();
<a name="line140"></a>  var simpleTimeZone = goog.i18n.TimeZone.createTimeZone(-480);
<a name="line141"></a>  assertEquals(-480, simpleTimeZone.getOffset(date));
<a name="line142"></a>  assertEquals(&#39;GMT+08:00&#39;, simpleTimeZone.getGMTString(date));
<a name="line143"></a>  assertEquals(&#39;Etc/GMT-8&#39;, simpleTimeZone.getTimeZoneId());
<a name="line144"></a>  assertEquals(&#39;UTC+8&#39;, simpleTimeZone.getLongName(date));
<a name="line145"></a>  assertEquals(&#39;UTC+8&#39;, simpleTimeZone.getShortName(date));
<a name="line146"></a>  assertEquals(&#39;+0800&#39;, simpleTimeZone.getRFCTimeZoneString(date));
<a name="line147"></a>  assertEquals(false, simpleTimeZone.isDaylightTime(date));
<a name="line148"></a>}
<a name="line149"></a>
<a name="line150"></a>function testSimpleTimeZoneZero() {
<a name="line151"></a>  var date = new Date();
<a name="line152"></a>  var simpleTimeZone = goog.i18n.TimeZone.createTimeZone(0);
<a name="line153"></a>  assertEquals(0, simpleTimeZone.getOffset(date));
<a name="line154"></a>  assertEquals(&#39;GMT+00:00&#39;, simpleTimeZone.getGMTString(date));
<a name="line155"></a>  assertEquals(&#39;Etc/GMT&#39;, simpleTimeZone.getTimeZoneId());
<a name="line156"></a>  assertEquals(&#39;UTC&#39;, simpleTimeZone.getLongName(date));
<a name="line157"></a>  assertEquals(&#39;UTC&#39;, simpleTimeZone.getShortName(date));
<a name="line158"></a>  assertEquals(&#39;+0000&#39;, simpleTimeZone.getRFCTimeZoneString(date));
<a name="line159"></a>  assertEquals(false, simpleTimeZone.isDaylightTime(date));
<a name="line160"></a>}
</pre>


</body>
</html>
